package _022_1_29

import "strconv"

func getOneIpNum(s string, id int) (int, int) {
	num := ""
	for i := id; i < len(s); i++ {
		if s[i] == '0' && len(num) == 0 {
			return i, i
		}

		n, _ := strconv.Atoi(num)
		if n > 255 {
			return i, i
		}
		num += string(s[i])
	}
	return -1, -1
}

func restoreIpAddresses2(s string) []string {
	id := 0
	strings := make([]string, 4)
	for i := 0; i < 4; i++ {
		num1, num2 := getOneIpNum(s, id)
		strings = append(strings, s[num1:num2+1])
	}
	return strings
}
